package com.sheliduan.itlearning.admin.controller;

import com.sheliduan.itlearning.admin.model.vos.user.DeleteUserReqVO;
import com.sheliduan.itlearning.admin.model.vos.user.FindUserPageListReqVO;
import com.sheliduan.itlearning.admin.model.vos.user.UpdateUserReqVO;
import com.sheliduan.itlearning.admin.service.AdminUserService;
import com.sheliduan.itlearning.common.aspect.ApiOperationLog;
import com.sheliduan.itlearning.common.model.vos.IdReqVO;
import com.sheliduan.itlearning.common.utils.PageResponseData;
import com.sheliduan.itlearning.common.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: 断舍离
 * @date: 2025/2/13 9:12
 * @description: 后台管理员用户管理控制器
 **/
@RestController
@RequestMapping("/admin")
public class AdminUserController {

    @Autowired
    private AdminUserService adminUserService;

    /*
    * 根据角色获取用户分页数据
    * */
    @PostMapping("/user/pageList")
    @ApiOperationLog(description = "获取用户分页数据接口")
    public PageResponseData findUserPageList(@RequestBody @Validated FindUserPageListReqVO reqVO, HttpServletRequest request){
        return adminUserService.findUserPageList(reqVO);
    }

    /*
     * 根据id修改用户
     * */
    @PostMapping("/user/update")
    @ApiOperationLog(description = "修改用户接口")
    public ResponseData updateUser(@RequestBody @Validated UpdateUserReqVO updateUserReqVO) {
        return adminUserService.updateUser(updateUserReqVO);
    }

    /*
     * 根据id删除用户
     * */
    @PostMapping("/user/delete")
    @ApiOperationLog(description = "修改用户接口")
    public ResponseData deleteUser(@RequestBody @Validated DeleteUserReqVO deleteUserReqVO) {
        return adminUserService.deleteUser(deleteUserReqVO);
    }

    /*
     * 根据id查找用户
     * */
    @PostMapping("/user/selectById")
    @ApiOperationLog(description = "根据id查找用户")
    public ResponseData selectById(@RequestBody @Validated IdReqVO idReqVO) {
        return adminUserService.selectById(idReqVO.getId());
    }
}
